package com.lmiot.xyclick.Util;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.google.gson.Gson;
import com.lmiot.xyclick.Bean.NoteBean;
import com.lmiot.xyclick.Bean.NoteBeanList;
import java.util.Random;

public class NoteUtil {
    public static void SaveData(Context context, String str, String str2) {
        NoteBean noteBean = new NoteBean(new Random().nextInt(10000), str, str2);
        NoteBeanList GetSaveData = GetSaveData(context);
        if (GetSaveData == null) {
            GetSaveData = new NoteBeanList();
        }
        GetSaveData.add(noteBean);
        SharedPreferences.Editor edit = context.getSharedPreferences("noteData", 0).edit();
        edit.putString("noteList", new Gson().toJson(GetSaveData));
        edit.commit();
    }

    public static void EditData(Context context, NoteBeanList noteBeanList) {
        SharedPreferences.Editor edit = context.getSharedPreferences("noteData", 0).edit();
        edit.putString("noteList", new Gson().toJson(noteBeanList));
        edit.commit();
    }

    public static NoteBeanList GetSaveData(Context context) {
        String string = context.getSharedPreferences("noteData", 0).getString("noteList", "");
        if (!TextUtils.isEmpty(string)) {
            return (NoteBeanList) new Gson().fromJson(string, NoteBeanList.class);
        }
        return null;
    }
}
